package com.zhisolution.zhicms;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.zhisolution.zhicms.model.cms_config;
import com.zhisolution.zhicms.model.sys_column;
import com.zhisolution.zhicms.model.sys_log;
import com.zhisolution.zhicms.model.sys_user;

public class ZhiCmsConfig extends JFinalConfig {

	/**
	 * 配置常量
	 */
	public void configConstant(Constants me) {
		loadPropertyFile("config.txt");
		me.setDevMode(getPropertyToBoolean("devMode", false));
	}

	/**
	 * 配置路由
	 */
	public void configRoute(Routes me) {
		/**** 后台 ****/
		me.add("/admin", com.zhisolution.zhicms.admin.LoginController.class);
		me.add("/admin/index", com.zhisolution.zhicms.admin.IndexController.class);
		me.add("/admin/column", com.zhisolution.zhicms.admin.column.ColumnContrlooer.class);
		me.add("/admin/content", com.zhisolution.zhicms.admin.content.ContentContrlooer.class);
		/**** 前台 ****/

	}

	/**
	 * 配置插件
	 */
	public void configPlugin(Plugins me) {
		// 配置C3p0数据库连接池插件
		C3p0Plugin cp = new C3p0Plugin(getProperty("jdbc.url"), getProperty("jdbc.username"), getProperty("jdbc.password").trim());
		me.add(cp);
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
		arp.setShowSql(true);
		me.add(arp);

		arp.addMapping("cms_config", cms_config.class);
		arp.addMapping("sys_column", sys_column.class);
		arp.addMapping("sys_log", sys_log.class);
		arp.addMapping("sys_user", sys_user.class);
	}

	/**
	 * 配置全局拦截器
	 */
	public void configInterceptor(Interceptors me) {
		me.add(new ZhiCmsInterceptor());
		
	}

	/**
	 * 配置处理器
	 */
	public void configHandler(Handlers me) {
		me.add(new ContextPathHandler("basePath"));
	}

	/**
	 * 系统启动完成后回调
	 */
	public void afterJFinalStart() {

		// FreeMarkerRender.getConfiguration().setSharedVariable("base",
		// getRequest().getScheme() + "://" + getRequest().getServerName() + ":"
		// + getRequest().getServerPort() + getRequest().getContextPath());
	}

	/**
	 * 系统关闭前回调
	 */
	public void beforeJFinalStop() {
	}
}